package com.andnnl.springbootdemo.action;

import com.andnnl.springbootdemo.utils.JsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Spring Boot Demo
 * Created by chenss on 2019/2/28.
 */
@RestController
public class HelloController {
    @Value("${name}")
    private String name;
    private static Logger log= LoggerFactory.getLogger(HelloController.class);

    @RequestMapping(value = "/hello")
    public String hello(){
        log.info("method hello 1234567890");
//        int x=1/0;
        return "Hello Spring Boot!~~~~~~右 枯地苛夺 苛df";
    }

    @RequestMapping(value = "/helloRest/{id}")
    public Map<String, Object> helloRest(@PathVariable String id,@RequestParam String name){
        log.info("method helloRest 1234567890 成功,id:{},name:{}",id,name);
//        int x=1/0;
//        Map<String,Object> map=new HashMap<>();
//        return map;
        return JsonBuilder.builder()
                .put("code",200)
                .put("msg","成功3w333,id:"+id+",name:"+name)
                .buildMap();
    }

    @RequestMapping(value = "/helloJson/{id}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> helloJson(@PathVariable String id,@RequestParam String name){
        log.info("method helloJson 1234567890 成功,id:{},name:{}",id,name);
//        int x=1/0;
//        Map<String,Object> map=new HashMap<>();
//        return map;
        return JsonBuilder.builder()
                .put("code",200)
                .put("msg","成功3w333,id:"+id+",name:"+name)
                .buildMap();
    }

    /**
     *
     * @return
     */
    @RequestMapping(value = "/hello3")
    public Map<String, Object> hello3(){
        log.info(name+"method hello3 123456782293222dd22 成功");
//        int x=1/0;
//        Map<String,Object> map=new HashMap<>();
//        return map;
        return JsonBuilder.builder()
                .put("code",200)
                .put("msg","成功3422dd222")
                .buildMap();
    }
}
